Project

library(tidyverse)
library(p8105.datasets)

1
## [1] 1
library(plotly)

Focus on NYC Airbnb data

library(p8105.datasets)

data("instacart")

instacart = instacart |> 
  janitor::clean_names() |> 
  mutate(
    order_dow = 
      case_match(
        order_dow, 
        1 ~ "Mon", 
        2 ~ "Tues",
        3 ~ "Wed",
        4 ~ "Thurs",
        5 ~ "Fri",
        6 ~ "Sat",
        0 ~ "Sun"),
    order_dow = as.factor(order_dow)) |> 
  mutate(day_week = forcats::fct_relevel(order_dow, c("Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun")))

A line plot showing the counts of items in each aisle

instacart |> 
  count(aisle) |> 
  filter(n > 10000) |> 
  mutate(aisle = fct_reorder(aisle, n)) |> 
  mutate(rank = min_rank(desc(n))) |> 
  arrange(desc(n)) |>
  plot_ly(
    x = ~aisle, y = ~n, type = "scatter", mode = "markers",
    alpha = 0.5)

A bar plot show what aisle had the most sale during a week.

try_df =
  instacart |> 
  count(aisle) |> 
  filter(n > 10000) 
  
bar_plot =  
  inner_join(try_df, instacart, by = "aisle") |> 
  mutate(order_dow = fct_reorder(order_dow, n)) |> 
  plot_ly(x = ~order_dow, y = ~n, color = ~order_dow, type = "bar", colors = "viridis")  

bar_plot

A scatter plot!

instacart |> 
  group_by(order_dow, order_hour_of_day) |> 
  summarise(avg_orders = n()) |> 
  arrange(order_dow,
  order_hour_of_day) |> 
  plot_ly(x= ~order_hour_of_day,
          y= ~avg_orders,
          color = ~order_dow,
          type = "scatter", mode = "markers",
     text = ~order_hour_of_day, alpha = 0.5)
## `summarise()` has grouped output by 'order_dow'. You can override using the `.groups`
## argument.